<html>
<head>
	<script type="text/javascript">
		var aJaxURL	= "server-side/operations/subtract.action.php";						//server side folder url
		var seoyURL = "server-side/seoy/seoy.action.php";						    	//server side folder url
		var upJaxURL= "server-side/upload/file.action.php";
		var tName	= "example";													    //table name
		var fName	= "add-edit-form";												    //form name
		    	
		$(document).ready(function () {        	
			LoadTable();	
						
			/* Add Button ID, Delete Button ID */
			GetButtons("add_button", "");		
			$("#add_button").button({
	            icons: {
	                primary: "ui-icon-arrowstop-1-s"
	            }
        	});	
			SetEvents("add_button", "", "", "", fName, aJaxURL);
		});

        //SeoYyy
		$(document.body).click(function (e) {
        	$("#prod_name").autocomplete("close");
        });
        
        
		function LoadTable(){
			var menuLength = [[ -1, 15, 30, 50], [ "ყველა", 15, 30, 50]];
			
			/* Table ID, aJaxURL, Action, Colum Number, Custom Request, Hidden Colum, Menu Array */
			GetDataTable(tName, aJaxURL, "get_list", 5, "", 0, menuLength, 1, "desc");

		}
		
		function LoadDialog(){
			var id		= $("#sub_id").val();

			/* Dialog Form Selector Name, Buttons Array */
			GetDialog(fName, 450, "auto", "");
			SeoY("prod_name", seoyURL, "subtract_prod_name", "", 0);
		}
		
	    // Add - Save
	    $(document).on("click", "#save-dialog", function () {
		    param 			= new Object();
			
		    param.act			="save_subtract";
	    	param.id			= $("#sub_id").val();
	    	param.obj_id        = $("#obj_id").val();
	    	param.prod_name		= $("#prod_name").val();
	    	param.qnt   		= $("#quantity").val();
			
			if(param.cat == ""){
				alert("შეავსეთ პროდუქტის დასახელების ველი!");
			}else {
			    $.ajax({
			        url: aJaxURL,
				    data: param,
			        success: function(data) {			        
						if(typeof(data.error) != 'undefined'){
							if(data.error != ''){
								alert(data.error);
							}else{
								LoadTable();
				        		CloseDialog(fName);
							}
						}
				    }
			    });
			}
		});

		$(document).on("keyup", "#quantity", function() {
		    var val = $(this).val();
		    if(isNaN(val)){
			    alert("შეიყვანეთ მხოლოდ ციფრები");
		         val = val.replace(/[^0-9\.]/g,'');
		         if(val.split('.').length>2) 
		             val =val.replace(/\.+$/,"");
		    }
		    $(this).val(val); 
		});
		//--SeoY
	    $(document).on("click", ".combobox", function (event) {
	    	var i = $(this).text();
			$("#" + i).autocomplete( "search", "" );
		});
    </script>
</head>

<body>
    <div id="dt_example" class="ex_highlight_row">
        <div id="container" class="category_table" style="width:80% !important;">        	
            <div id="dynamic">
            	<h2 align="center">ჩამოწერები</h2>
            	<div id="button_area">
        			<button id="add_button">ჩამოწერა</button>
        		</div>
                <table class="display" id="example">
                    <thead>
                        <tr id="datatable_header">
                            <th>ID</th>
                            <th>თარიღი</th>
                            <th>მომხმარებელი</th>
                            <th>პროდუქტის დასახელება</th>
                            <th>რაოდენობა</th>
                        </tr>
                    </thead>
                    <thead>
                        <tr class="search_header">
                            <th class="colum_hidden">
                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_user" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_prod" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_quantity" value="ფილტრი" class="search_init" />
                            </th>
                        </tr>
                    </thead>
                </table>
            </div>
            <div class="spacer">
            </div>
        </div>

    </div>
    
    <!-- jQuery Dialog -->
    <div id="add-edit-form" class="form-dialog" title="პროდუქტი">
    	<!-- aJax -->
	</div>
	
</body>
</html>